// api/ai_role_api/ai_role_remove.go
package ai_role_api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"muziai-server/global"
	"muziai-server/models"
	"muziai-server/utils/res"
)

// AiRoleWorkRemoveView 角色工单删除
func (AiRoleApi) AiRoleWorkRemoveView(c *gin.Context) {
	var cr models.IDListRequest
	err := c.ShouldBindJSON(&cr)
	if err != nil {
		res.FailWithError(c, err)
		return
	}
	var workList []models.AiRoleWorkOrderModel
	global.DB.Find(&workList, "id in ?", cr.IDList)

	if len(workList) > 0 {
		global.DB.Delete(&workList)
	}
	msg := fmt.Sprintf("删除工单 %d 条，成功 %d 条", len(cr.IDList), len(workList))
	logrus.Infof(msg)

	res.OkWithMsg(c, msg)
}
